home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / BORL_TIP / TI1000 / TI1729.ASC < prev    next >
Text File  |  1993-10-21  |  5KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Pascal                                NUMBER  :  1729
  9.   VERSION  :  All
  10.        OS  :  DOS
  11.      DATE  :  October 21, 1993                         PAGE  :  1/4
  12.  
  13.     TITLE  :  Having two Turbo Vision dialogs on the screen at once
  14.  
  15.  
  16.  
  17.  
  18.   {
  19.     The following  program demonstrates one technique for placing
  20.     two dialogs on the screen at the same time in a Turbo Vision
  21.     application. The key to this process is to make the first
  22.     dialog a modeless dialog, and then the second can be either
  23.     modal or modeless, depending on your needs. In this case,
  24.     the second dialog is modal.
  25.  
  26.     When a modal dialog is on the screen, the user must close it
  27.     before getting access to the other features in an application.
  28.     For instance, a user cannot use the main programs menu while
  29.     modal dialog is on the screen. This is not true of modeless
  30.     dialogs. Modal dialogs are started with ExecView or ExecDialog.
  31.     Modeless dialogs are "Inserted" into the desktop.
  32.   }
  33.  
  34.   {$X+}
  35.   Program TwoDlgs;
  36.  
  37.   Uses
  38.     App,
  39.     Dialogs,
  40.     Drivers,
  41.     Menus,
  42.     MsgBox,
  43.     Views,
  44.     Objects;
  45.  
  46.   const
  47.     cmDialogBox = 101;
  48.     cmPress2 = 102;
  49.  
  50.   type
  51.     Consistency = (Solid, Runny, Melted);
  52.     Cheese = (None, Hvarti, Tilset, Jarlsberg);
  53.  
  54.  
  55.     PTrainDialog = ^TTrainDialog;
  56.     TTrainDialog = Object(TDialog)
  57.       constructor Init(Bounds: TRect; ATitle: String);
  58.       procedure HandleEvent(var Event: TEvent); virtual;
  59.       procedure Press2;
  60.     end;
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Pascal                                NUMBER  :  1729
  75.   VERSION  :  All
  76.        OS  :  DOS
  77.      DATE  :  October 21, 1993                         PAGE  :  2/4
  78.  
  79.     TITLE  :  Having two Turbo Vision dialogs on the screen at once
  80.  
  81.  
  82.  
  83.  
  84.     TMyApp = Object(TApplication)
  85.       constructor Init;
  86.       procedure InitMenuBar; virtual;
  87.       procedure InitStatusLine; virtual;
  88.       procedure HandleEvent(var Event: TEvent); virtual;
  89.       procedure DialogBox;
  90.     end;
  91.  
  92.   constructor TTrainDialog.Init(Bounds: TRect; ATitle: String);
  93.   var
  94.     R: TRect;
  95.     Control: PView;
  96.   begin
  97.     TDialog.Init(Bounds, ATitle);
  98.  
  99.     R.Assign(2, (Bounds.B.Y - Bounds.A.Y) - 12,
  100.        (Bounds.B.X - Bounds.A.X) - 2,
  101.        (Bounds.B.Y - Bounds.A.Y) - 3);
  102.     Insert(New(PButton, Init(R, 'Click Here',
  103.        cmPress2, bfNormal)));
  104.   end;
  105.  
  106.   procedure TTrainDialog.HandleEvent(var Event: TEvent);
  107.   begin
  108.     TDialog.HandleEvent(Event);
  109.     if Event.What = EvCommand then begin
  110.       case Event.Command of
  111.         cmPress2: Press2;
  112.         else Exit;
  113.       end;
  114.       ClearEvent(Event);
  115.     end;
  116.   end;
  117.  
  118.   procedure TTrainDialog.Press2;
  119.   var
  120.     D: PDialog;
  121.     R: TRect;
  122.     Control: Word;
  123.   begin
  124.     R.Assign(48,3,74,14);
  125.     D := New(PDialog, Init(R, 'Another Dialog'));
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Pascal                                NUMBER  :  1729
  141.   VERSION  :  All
  142.        OS  :  DOS
  143.      DATE  :  October 21, 1993                         PAGE  :  3/4
  144.  
  145.     TITLE  :  Having two Turbo Vision dialogs on the screen at once
  146.  
  147.  
  148.  
  149.  
  150.     R.Assign(4, 2, 22, 10);
  151.     D^.Insert(New(PButton, Init(R, 'Click To Close',
  152.         cmOk, bfDefault)));
  153.  
  154.     Control := DeskTop^.ExecView(D);
  155.     Dispose(D, Done);
  156.   end;
  157.  
  158.   constructor TMyApp.Init;
  159.   var
  160.     R: TRect;
  161.   begin
  162.     TApplication.Init;
  163.   end;
  164.  
  165.   procedure TMyApp.HandleEvent(var Event: TEvent);
  166.   begin
  167.     TApplication.HandleEvent(Event);
  168.     if Event.What = EvCommand then begin
  169.       case Event.Command of
  170.         cmDialogBox: DialogBox;
  171.       else
  172.         Exit;
  173.       end;
  174.       ClearEvent(Event);
  175.     end;
  176.   end;
  177.  
  178.   procedure TMyApp.InitMenuBar;
  179.   var
  180.     R: TRect;
  181.   begin
  182.     GetExtent(R);
  183.     R.B.Y := R.A.Y + 1;
  184.     MenuBar := New(PMenuBar, Init(R, NewMenu(
  185.       NewSubMenu('~F~ile', hcNoContext, NewMenu(
  186.         NewItem('~D~ialogs', 'Alt-D', kbAltD,
  187.              cmDialogBox, hcNoContext,
  188.         NewLine(
  189.         NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  190.         nil)))),
  191.       nil))
  192.     ));
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Pascal                                NUMBER  :  1729
  207.   VERSION  :  All
  208.        OS  :  DOS
  209.      DATE  :  October 21, 1993                         PAGE  :  4/4
  210.  
  211.     TITLE  :  Having two Turbo Vision dialogs on the screen at once
  212.  
  213.  
  214.  
  215.  
  216.   end;
  217.  
  218.   procedure TMyApp.InitStatusLine;
  219.   var R: TRect;
  220.   begin
  221.     GetExtent(R);
  222.     R.A.Y := R.B.Y - 1;
  223.     StatusLine := New(PStatusLine, Init(R,
  224.       NewStatusDef(0, $FFFF,
  225.         NewStatusKey('', kbF10, cmMenu,
  226.         NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  227.         NewStatusKey('~Alt-D~ Dialog', kbAltD, cmDialogBox,
  228.         NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
  229.         nil)))),
  230.       nil)
  231.     ));
  232.   end;
  233.  
  234.   procedure TMyApp.DialogBox;
  235.   var
  236.     R: TRect;
  237.     D: PDialog;
  238.     Control: Word;
  239.   begin
  240.     R.Assign(20,5,60,21);
  241.     D := New(PTrainDialog, Init(R, 'Training Dialog'));
  242.     DeskTop^.Insert(D);
  243.   end;
  244.  
  245.   var
  246.     A: TMyApp;
  247.   begin
  248.     A.Init;
  249.     A.Run;
  250.     A.Done;
  251.   end.
  252.  
  253.  
  254.   DISCLAIMER: You have the right to use this technical information
  255.   subject to the terms of the No-Nonsense License Statement that
  256.   you received with the Borland product to which this information
  257.   pertains.
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.